#include "Point2D.h"
#include "../GameLib.h"
#include <math.h>
#include "../Str.h"
#include "../../OpenGL.h"

Point2D::Point2D(){x=0.0;y=0.0;}
Point2D::Point2D(double x,double y){this->x=x;this->y=y;}
Point2D::~Point2D(){}
Point2D& Point2D::set(double x,double y){this->x=x;this->y=y;return *this;}
double Point2D::getX(){return x;}
double Point2D::getY(){return y;}
Point2D& Point2D::setX(double x){this->x=x;return *this;}
Point2D& Point2D::setX(Point2D &pt){x=pt.getX();return *this;}
Point2D& Point2D::setY(double y){this->y=y;return *this;}
Point2D& Point2D::setY(Point2D &pt){y=pt.getY();return *this;}
double Point2D::distance(Point2D &pt){return sqrt(pow(x-pt.getX(),2.0)+pow(y-pt.getY(),2.0));}
double Point2D::directionR(Point2D &pt){return atan2(y-getY(),x-getX());}
double Point2D::directionD(Point2D &pt){
    double a;
    a=RAD2DEG(directionR(pt));
    if (a<0){a+=360.0;}
    return a;
}
Point2D& Point2D::copy(Point2D &pt){x=pt.getX();y=pt.getY();return *this;}
Point2D& Point2D::add(Point2D &pt){x+=pt.getX();y+=pt.getY();return *this;}
Point2D& Point2D::sub(Point2D &pt){x-=pt.getX();y-=pt.getY();return *this;}
bool Point2D::isEq(Point2D &pt){return (x==pt.getX()&&y==pt.getY())?true:false;}
bool Point2D::isNeq(Point2D &pt){return !isEq(pt);}
Point2D& Point2D::operator+=(Point2D &pt){return add(pt);}
Point2D& Point2D::operator-=(Point2D &pt){return sub(pt);}
Point2D& Point2D::operator=(Point2D &pt){return copy(pt);}
bool Point2D::operator==(Point2D &pt){return isEq(pt);}
bool Point2D::operator!=(Point2D &pt){return isNeq(pt);}
Str& Point2D::toString(Str &temp){
    temp.clear();
    temp<<"("<<x<<", "<<y<<")";
    return temp;
}
/*bool Point2D::isWithin(BasicRect &rect)
{
    return rect.captures(this);
}

Point2D& closestPoint2D(BasicRect &rect, Point2D &to)
{
    rect.closestPoint2D(this,to);
}*/
void Point2D::draw(double depth){
    glBegin(GL_POINTS);
    glVertex3f((float)x,(float)y,(float)depth);
    glEnd();
}
void Point2D::draw_color(double depth, int hexColor){
    float c[4];
    gameLib.getColorA(c);
    gameLib.setColor(hexColor);
    draw(depth);
    gameLib.setColorA(c);
}
void Point2D::draw_size(double depth, double radius){
    gameLib.setPointSize(radius);
    draw(depth);
}
void Point2D::draw_sizeColor(double depth, double radius, int hexColor){
    gameLib.setPointSize(radius);
    draw_color(depth,hexColor);
}
